/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.zhpan.bannerview;

import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.RecycleItemProvider;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;
import ohos.app.Context;

/**
 * SampleAdapter
 *
 * @since 2021-03-24
 */
public class SampleAdapter extends RecycleItemProvider {
    private static final int FIVETEEN = 15;
    private static final int FIVETY = 50;
    private String[] mDataSet;
    private Context context;

    /**
     * SampleAdapter
     *
     * @param context 參數
     * @param dataSet 參數
     */
    public SampleAdapter(Context context, String[] dataSet) {
        this.mDataSet = dataSet;
        this.context = context;
    }

    @Override
    public int getCount() {
        return mDataSet.length;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public Component getComponent(int i1, Component component, ComponentContainer componentContainer) {
        DirectionalLayout dependentLayout = new DirectionalLayout(context);
        DirectionalLayout.LayoutConfig layoutConfig = new DirectionalLayout.LayoutConfig(
            ComponentContainer.LayoutConfig.MATCH_PARENT, ComponentContainer.LayoutConfig.MATCH_PARENT);
        dependentLayout.setLayoutConfig(layoutConfig);
        Text text = new Text(context);
        text.setText(mDataSet[i1]);
        text.setTextColor(Color.BLACK);
        text.setTextSize(FIVETY);
        text.setPadding(FIVETEEN, FIVETEEN, FIVETEEN, FIVETEEN);
        text.setMultipleLine(true);
        text.setLayoutConfig(new ComponentContainer.LayoutConfig(
            ComponentContainer.LayoutConfig.MATCH_PARENT, ComponentContainer.LayoutConfig.MATCH_CONTENT));
        dependentLayout.addComponent(text);
        return dependentLayout;
    }
}
